<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>图灵谷-内容管理-问卷管理</title>
<div th:replace="fragments/head_admin">head</div>
</head>
<body class="pace-done fixed-sidebar">
	<div id="wrapper">
		<div th:replace="fragments/menu_admin::menu(root=content,current=question)">菜单栏</div>
		<div id="page-wrapper" class="gray-bg">
			<div th:replace="fragments/nav_admin">导航栏</div>
			<div th:replace="fragments/breadcrumbs_admin::breadcrumbs(parent=内容管理,current=问卷管理)">面包屑栏</div>
			<div class="wrapper wrapper-content animated fadeInRight">
				<div class="row">
					<div class="col-lg-4">
						<div class="ibox float-e-margins" id="infos">
							<div class="ibox-title">
								<h5>问卷管理</h5>
							</div>
							<div class="ibox-content">
								<div class="row m-b-sm m-t-sm">
									<form th:action="@{/admin/m/ext/question/list.gsp}" id="dataTableFilterForm" role="form" action="#" method="post">
										<input type="hidden" name="nodeId" /> <input type="hidden" name="infoModelId" />
										<div class="col-md-2">
											<a th:href="@{/admin/m/ext/question/add.gsp}" data-target="#commonWin" class="btn btn-primary btn-sm" type="button" data-toggle="modal"><i class="fa fa-plus"></i>&nbsp;新增</a>
										</div>
										<div class="col-md-10">
											<div class="input-group">
												<input type="text" hidden="true" /> <input name="simpleQueryParam" type="text" placeholder="请输入关键字搜索" class=" form-control" /> <span class="input-group-btn">
													<button onclick="myTable.filter()" type="button" class="btn btn-sm btn-primary">搜索</button>
												</span>
											</div>
										</div>
									</form>
								</div>
								<table class="table table-striped table-hover">
									<thead>
										<tr>
											<th>#</th>
											<th>状态</th>
											<th>标题</th>
											<th width="80">操作</th>
										</tr>
									</thead>
									<tbody id="dataTableDiv">
									</tbody>
								</table>
								<div id="dataTablePageDiv" class="text-right"></div>
							</div>
						</div>
					</div>
					<div class="col-lg-8" th:if="${question} == null">
						<div class="ibox float-e-margins" id="infos">
							<div class="ibox-title">
								<h5>选项管理</h5>
								<div class="ibox-tools">
									<a th:href="@{/admin/m/ext/question/addItem.gsp}" data-target="#commonItemWin" class="btn btn-primary btn-sm" disabled='disabled' id="addItem" type="button" data-toggle="modal"><i class="fa fa-plus"></i>&nbsp;新增</a>
								</div>
							</div>
							<div class="ibox-content">
								<div class="row m-b-sm m-t-sm">
									<form th:action="@{/admin/m/ext/question/questionList.gsp}" id="dataQuestionTableFilterForm" role="form" action="#" method="post">
										<input type="hidden" name="id" />
									</form>
								</div>
								<div id="questionDataTableDiv"></div>
								<div class="row m-b-sm m-t-sm">
									<form th:action="@{/admin/m/ext/question/itemList.gsp}" id="dataItemTableFilterForm" role="form" action="#" method="post">
										<input type="hidden" name="questionId" />
									</form>
								</div>
								<div class="table-responsive" id="itemDataTableDiv"></div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div th:replace="fragments/footer_admin">底部</div>
		</div>
	</div>
</body>
<div th:replace="fragments/import_js_admin">引入js</div>
<!--/* 模板引擎生成数据 */-->
<script th:inline="javascript" id="dataItemTableTpl" type="text/html">
<![CDATA[ */
<br />
{{# 
if(d.length > 0){

var editUrlPre= /*[[@{/admin/m/ext/question/editOption_}]]*/'url'; 
var ItemEditUrlPre= /*[[@{/admin/m/ext/question/editItem_}]]*/'url'; 

var addOptionPre = /*[[@{/admin/m/ext/question/addOption_}]]*/'url'; 
for(var i = 0; i < d.length; i++){ var record=d[i];var num=i+1; }}
	<div class="ibox float-e-margins">
		<div class="ibox-title">
		        	{{record.title}}[
					{{# if(record.type===1){ }}
						<span class="text-danger">问答</span>
		  	 		{{# } else if(record.type===2 && record.maxSelected > 1){ }}
						<span class="text-danger">多选(最多可选{{record.maxSelected}}项)</span>
		  	 		{{# } else if(record.type===2 && record.maxSelected == 0){ }}
						<span class="text-danger">多选(不限选项)</span>
		  	 		{{# } else if(record.type===2 && record.maxSelected == 1){ }}
						<span class="text-danger">单选</span>
		  	 		{{# } }}]
        	<div class="ibox-tools">
				<a href="{{addOptionPre+record.id}}.gsp" data-target="#commonOptionWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-plus"></i></a>
				<a href="{{ItemEditUrlPre+record.id}}.gsp" data-target="#commonItemWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-edit"></i></a>
				<button class="btn btn-warning btn-xs" type="button" onclick="deleteItem('{{record.id}}')"><i class="fa fa-trash-o"></i></button>
			</div>
		</div>
		<div class="ibox-content">
	<table class="table invoice-table">
<tbody>
	{{# for(var j = 0; j < record.questionOptions.length; j++) {
		var optionRecord=record.questionOptions[j];}}
		<tr>
        <td>
            <div>{{optionRecord.title}}</div>
        </td>
        <td>{{optionRecord.titleinputField||''}}</td>
        <td>{{optionRecord.selectCount}}</td>
		<td>
			<a href="{{editUrlPre+optionRecord.id}}.gsp" data-target="#commonOptionWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-edit"></i></a>
			<button class="btn btn-warning btn-xs" type="button" onclick="deleteOption('{{optionRecord.id}}')"><i class="fa fa-trash-o"></i></button>
		</td>
    </tr>
	{{# } }}
</tbody>
</table>
</div>
</div>
{{# } }}
{{# }else{ }}
    <tr><td colspan="9"><br/><div class="alert alert-danger alert-dismissable">对不起，暂时没有数据可以显示，请更换查询条件重新再试！ <div></td></tr>
{{# } }}
</script>
<!--/* 模板引擎生成数据 */-->
<script th:inline="javascript" id="dataQuestionTableTpl" type="text/html">
{{# }}
<div class="col-lg-6">
	<dl class="dl-horizontal">
		<dt>问卷标题：</dt>
		<dd>{{d.title||""}}</dd>
		<dt>问卷模式：</dt>
		<dd>
			{{# if(d.mode===1){ }}
				<span class="text-success">独立访问</span>
   	 		{{# } }}
			{{# if(d.mode===2){ }}
				<span class="text-danger">独立IP</span>
			{{# } }}
			{{# if(d.mode===3){ }}
				<span>独立用户</span>
			{{# } }}
		</dd>
		<dt>开始时间：</dt>
		<dd>{{d.startTime||""}}</dd>
		<dt>状　　态：</dt>
		<dd>
			{{# if(d.enabled===1){ }}
				<span class="text-success">启用</span>
   	 		{{# } }}
			{{# if(d.enabled===2){ }}
				<span class="text-danger">停用</span>
			{{# } }}
		</dd>
	</dl>
</div>
<div class="col-lg-6" id="cluster_info">
	<dl class="dl-horizontal">
		<dt>问卷编码：</dt>
		<dd>{{d.codeNum||""}}</dd>
		<dt>总票数：</dt>
		<dd>{{d.totalCount||0}}</dd>
		<dt>结束时间：</dt>
		<dd>{{d.endTime||""}}</dd>
	</dl>
</div>
{{# }}
</script>
<!--/* 模板引擎生成数据 */-->
<script th:inline="javascript" id="dataTableTpl" type="text/html">
<![CDATA[*/
{{# 
var editUrlPre= /*[[@{/admin/m/ext/question/edit_}]]*/'url'; 
var len = d.records.length;
if(len>0){
	for(var i = 0; i < len; i++){ 
		var record=d.records[i];
		var num=d.pageSize*(d.page-1)+i+1;
	}}
<tr class="gradeX">
	<td>{{num}}</td>
	<td>
		{{# if(record.enabled===1){ }}
			<input type="checkbox" data-size="mini" data-toggle="toggle" class="js-switch" data-on="启用" data-off="停用" checked="checked" onchange="myTable.changeEnabled(this, '{{record.id}}')" /> 
   	 	{{# }else{ }}
			<input type="checkbox" data-size="mini" data-toggle="toggle" class="js-switch" data-on="启用" data-off="停用" onchange="myTable.changeEnabled(this, '{{record.id}}')" />
		{{# } }}
	</td>
	<td><a onclick="renderItem('{{record.id}}')">{{record.title}}</a></td>
	<td>
		<a href="{{editUrlPre+record.id}}.gsp" data-target="#commonWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-edit"></i></a>
		<button class="btn btn-warning btn-xs" type="button" onclick="myTable.deleteItem('{{record.id}}')"><i class="fa fa-trash-o"></i></button>
	</td>
</tr>
	{{# } }}
{{# }else{ }}
    <tr><td colspan="9"><br/><div class="alert alert-danger alert-dismissable">对不起，暂时没有数据可以显示，请更换查询条件重新再试！ <div></td></tr>
{{# } }}
</script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var setting = {
        deleteUrl : /*[[@{/admin/m/ext/question/delete_}]]*/'url',
        enableUrl : /*[[@{/admin/m/ext/question/enable_}]]*/'url',
        disableUrl : /*[[@{/admin/m/ext/question/disable_}]]*/'url',
        enabledChange : true, //修改是否可用
        dataTableTpl : 'dataTableTpl', //模板
        dataTableDiv : 'dataTableDiv', //表格
        dataTableFilterForm : 'dataTableFilterForm', //过滤表单
        dataTablePageDiv : 'dataTablePageDiv', //分页
        pageable : true, //分页
        page : 1
    };
    var myTable = new TG_Tabel.createNew(setting);
    var questionSetting = {
        deleteUrl : /*[[@{/admin/m/ext/question/delete_}]]*/'url',
        dataTableTpl : 'dataQuestionTableTpl', //模板
        dataTableDiv : 'questionDataTableDiv', //表格
        dataTableFilterForm : 'dataQuestionTableFilterForm' //过滤表单
    };
    var myQuestionTable = new TG_Tabel.createNew(questionSetting);
    var itemSetting = {
        deleteUrl : /*[[@{/admin/m/ext/question/deleteOption_}]]*/'url',
        dataTableTpl : 'dataItemTableTpl', //模板
        dataTableDiv : 'itemDataTableDiv', //表格
        dataTableFilterForm : 'dataItemTableFilterForm' //过滤表单
    };
    var myItemTable = new TG_Tabel.createNew(itemSetting);
    $(function() {
        //初始化表格
        myTable.init();
        myQuestionTable.init();
        myItemTable.init();
    });
    /*]]>*/
</script>
<script th:inline="javascript">
    /*<![CDATA[*/
    function renderItem(id) {
        $('#addItem').attr('disabled', false);
        $('#dataQuestionTableFilterForm').find('input[name="id"]').val(id);
        myQuestionTable.refresh();
        $('#dataItemTableFilterForm').find('input[name="questionId"]').val(id);
        myItemTable.refresh();
    }
    function deleteItem(id) {
        var turl = /*[[@{/admin/m/ext/question/deleteItem_}]]*/'url';
        var url = turl + id + ".gsp";
        tg_dleteItem(url, myItemTable.refresh());
    }
    function deleteOption(id) {
        var turl = /*[[@{/admin/m/ext/question/deleteOption_}]]*/'url';
        var url = turl + id + ".gsp";
        tg_dleteItem(url, myItemTable.refresh());
    }
    /*]]>*/
</script>
<div th:replace="common/common_window::window(windowId=commonItemWin)">公共弹出窗口</div>
<div th:replace="common/common_window::window(windowId=commonOptionWin)">公共弹出窗口</div>
</html>